#define _CRT_SECURE_NO_WARNINGS
#include"test.h"

class Solution {
public:
    ListNode* detectCycle(ListNode* head)
    {
        set<ListNode*> s;
        ListNode* cur = head;
        while (cur != nullptr)
        {
            if (s.count(cur) == 1)
            {
                return cur;
            }
            else
            {
                s.insert(cur);
            }
            cur = cur->next;
        }
        return nullptr;
    }
};